package org.pub.app.lunch;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import android.os.Parcel;
import android.os.Parcelable;

/**
<?xml version="1.0" encoding="utf-8" ?> 
- <Response>
- <Header>
  <Service>GetAvailList</Service> 
  <Version>1.0</Version> 
  <Status>Sucess</Status> 
  </Header>
- <ResponseAirDomAvailListRS>
- <Avail>
  <AvailDepCity>GMP</AvailDepCity> 
  <AvailDepCityDesc>GMP</AvailDepCityDesc> 
  <AvailArrCity>CJU</AvailArrCity> 
  <AvailArrCityDesc>CJU</AvailArrCityDesc> 
  <AvailDepDate>20110912</AvailDepDate> 
+ <Segment>
  <CarCode>LJ</CarCode> 
  <CarDesc>진에어</CarDesc> 
  <MainFlt>0331</MainFlt> 
  <DepCity>GMP</DepCity> 
  <DepDesc>김포</DepDesc> 
  <DepDateTime>201109120645</DepDateTime> 
  <ArrCity>CJU</ArrCity> 
  <ArrDesc>제주</ArrDesc> 
  <ArrDateTime>201109120750</ArrDateTime> 
  <Currency>KRW</Currency> 
- <ClassDetail>
  <Class>Y</Class> 
  <NoSeat>0</NoSeat> 
  <Fare>80400</Fare> 
  <IdCode /> 
  <EventDcCode /> 
  <FareBasis /> 
  <ItinInfo>LJ/0331/201109120645/GMP/CJU/201109120750/Y/KRW//</ItinInfo> 
  </ClassDetail>
  </Segment>
*/

public class Segment implements Parcelable {
	private String CarCode = "";
	private String CarDesc = "";
	private String MainFlt = "";
	private String DepCity = "";
	private String DepDesc = "";
	private String DepDateTime = "";
	private String ArrCity = "";
	private String ArrDesc = "";
	private String ArrDateTime = "";
	private String ClassCode = "";
	private String StateCode = "";
	private String StateCodeDesc = "";
	private String NoOfSeat = "";
	private String Fare = "";
	private String ItinInfo = "";
	private String Currency = "";
	private String Session = "";

	public void writeToParcel(Parcel dest, int flags) {

		dest.writeString(CarCode);
		dest.writeString(CarDesc);
		dest.writeString(MainFlt);
		dest.writeString(DepCity);
		dest.writeString(DepDesc);
		dest.writeString(DepDateTime);
		dest.writeString(ArrCity);
		dest.writeString(ArrDesc);
		dest.writeString(ArrDateTime);
		dest.writeString(ClassCode);
		dest.writeString(StateCode);
		dest.writeString(StateCodeDesc);
		dest.writeString(NoOfSeat);
		dest.writeString(Fare);
		dest.writeString(ItinInfo);
		dest.writeString(Currency);
		dest.writeString(Session);
	}

	public int describeContents() {

		return 0;
	}

	public static final Parcelable.Creator<Segment> CREATOR = new Parcelable.Creator<Segment>() {

		public Segment createFromParcel(Parcel in) {
			Segment segment = new Segment();
			segment.CarCode = in.readString();
			segment.CarDesc = in.readString();
			segment.MainFlt = in.readString();
			segment.DepCity = in.readString();
			segment.DepDesc = in.readString();
			segment.DepDateTime = in.readString();
			segment.ArrCity = in.readString();
			segment.ArrDesc = in.readString();
			segment.ArrDateTime = in.readString();
			segment.ClassCode = in.readString();
			segment.StateCode = in.readString();
			segment.StateCodeDesc = in.readString();
			segment.NoOfSeat = in.readString();
			segment.Fare = in.readString();
			segment.ItinInfo = in.readString();
			segment.Currency = in.readString();
			segment.Session = in.readString();

			return segment;
		}

		public Segment[] newArray(int size) {
			return new Segment[size];
		}

	};

	public String getSession() {
		return Session;
	}

	public void setSession(String session) {
		if (session.indexOf("&lt;") != -1) {
			session = session.replaceAll("&lt;", "<").replaceAll("&gt;", ">");
		}
		Session = session;
	}

	public String getCurrency() {
		return Currency;
	}

	public void setCurrency(String currency) {
		Currency = currency;
	}

	public String getCarDesc() {
		return CarDesc;
	}

	public void setCarDesc(String carDesc) {
		CarDesc = carDesc;
	}

	public String getFare() {
		return Fare;
	}

	public void setFare(String fare) {
		Fare = fare;
	}

	public String getItinInfo() {
		return ItinInfo;
	}

	public void setItinInfo(String itinInfo) {
		ItinInfo = itinInfo;
	}

	public Segment() {

	}

	public Segment(Element elm) {

		this.CarCode = elm.getElementsByTagName("CarCode").item(0).getFirstChild().getNodeValue();
		this.CarDesc = elm.getElementsByTagName("CarDesc").item(0).getFirstChild().getNodeValue();
		this.MainFlt = elm.getElementsByTagName("MainFlt").item(0).getFirstChild().getNodeValue();

		this.DepCity = elm.getElementsByTagName("DepCity").item(0).getFirstChild().getNodeValue();
		this.DepDesc = elm.getElementsByTagName("DepDesc").item(0).getFirstChild().getNodeValue();
		this.ArrCity = elm.getElementsByTagName("ArrCity").item(0).getFirstChild().getNodeValue();
		this.ArrDesc = elm.getElementsByTagName("ArrDesc").item(0).getFirstChild().getNodeValue();

		this.DepDateTime = elm.getElementsByTagName("DepDateTime").item(0).getFirstChild().getNodeValue();
		this.ArrDateTime = elm.getElementsByTagName("ArrDateTime").item(0).getFirstChild().getNodeValue();
		this.Currency = elm.getElementsByTagName("Currency").item(0).getFirstChild().getNodeValue();

		NodeList ClassDetailList = elm.getElementsByTagName("ClassDetail");
		for (int i = 0; i < ClassDetailList.getLength(); i++) {
			Element ClassDetail = (Element) ClassDetailList.item(i);

			String fare = ClassDetail.getElementsByTagName("Fare").item(0).getFirstChild().getNodeValue();
			String noSeat = ClassDetail.getElementsByTagName("NoSeat").item(0).getFirstChild().getNodeValue();
			String classCode = ClassDetail.getElementsByTagName("Class").item(0).getFirstChild().getNodeValue();
			String ItinInfo = ClassDetail.getElementsByTagName("ItinInfo").item(0).getFirstChild().getNodeValue();
			if (fare.equals("0")) {
				//log.info(Segment.getChildText("CarCode") + Segment.getChildText("MainFlt") + " continue_fare : " + Fare);
				continue;
			}
			if (CarCode.equals("OZ")) {
				if (!classCode.equals("C") && !classCode.equals("Y")) {
					//log.info(CarCode + Segment.getChildText("MainFlt") + " continue_class : " + classCode);
					continue;
				}
			} else if (CarCode.equals("LJ")) {
				if (noSeat.equals("0")) {
					//log.info(CarCode + Segment.getChildText("MainFlt") + " continue_NoSeat : " + ClassDetail.getChildText("NoSeat"));
				}
			}

			this.NoOfSeat = noSeat;
			this.Fare = fare;
			this.ClassCode = classCode;
			this.ItinInfo = ItinInfo;
		}

	}

	public String getNoOfSeat() {
		return NoOfSeat;
	}

	public void setNoOfSeat(String noOfSeat) {
		NoOfSeat = noOfSeat;
	}

	public String getCarCode() {
		return CarCode;
	}

	public void setCarCode(String carCode) {
		CarCode = carCode;
	}

	public String getMainFlt() {
		return MainFlt;
	}

	public void setMainFlt(String mainFlt) {
		MainFlt = mainFlt;
	}

	public String getDepCity() {
		return DepCity;
	}

	public void setDepCity(String depCity) {
		DepCity = depCity;
	}

	public String getDepDesc() {
		return DepDesc;
	}

	public void setDepDesc(String depDesc) {
		DepDesc = depDesc;
	}

	public String getDepDateTime() {
		return DepDateTime;
	}

	public void setDepDateTime(String depDateTime) {
		DepDateTime = depDateTime;
	}

	public String getArrCity() {
		return ArrCity;
	}

	public void setArrCity(String arrCity) {
		ArrCity = arrCity;
	}

	public String getArrDesc() {
		return ArrDesc;
	}

	public void setArrDesc(String arrDesc) {
		ArrDesc = arrDesc;
	}

	public String getArrDateTime() {
		return ArrDateTime;
	}

	public void setArrDateTime(String arrDateTime) {
		ArrDateTime = arrDateTime;
	}

	public String getClassCode() {
		return ClassCode;
	}

	public void setClassCode(String class1) {
		ClassCode = class1;
	}

	public String getStateCode() {
		return StateCode;
	}

	public void setStateCode(String stateCode) {
		StateCode = stateCode;
	}

	public String getStateCodeDesc() {
		return StateCodeDesc;
	}

	public void setStateCodeDesc(String stateCodeDesc) {
		StateCodeDesc = stateCodeDesc;
	}

}
